package com.example.NeteaseCloudMusicApi.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.NeteaseCloudMusicApi.R;
import com.example.NeteaseCloudMusicApi.entity.News;
import com.example.NeteaseCloudMusicApi.ui.adapter.KtvAdapter;

import java.util.ArrayList;
import java.util.List;


public class KtvFragment extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    private List<News> news = new ArrayList<>();
    RecyclerView recyclerView;
    KtvAdapter adapter;

    public KtvFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment MyFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static KtvFragment newInstance(String param1, String param2) {
        KtvFragment fragment = new KtvFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView =  inflater.inflate(R.layout.ktv, container, false);
        initSong();
        recyclerView = rootView.findViewById(R.id.recyclerview1);
        recyclerView.setLayoutManager(new GridLayoutManager(getContext(),3));
        adapter = new KtvAdapter(news);
        recyclerView.setAdapter(adapter);
        return rootView;
    }

    private void initSong() {

        News news1 = new News("会不会", R.mipmap.k_works1);
        news.add(news1);
        News news2 = new News("烟火", R.mipmap.k_works2);
        news.add(news2);
        News news3 = new News("不染", R.mipmap.k_works3);
        news.add(news3);
    }

}